home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / Tools / Treiber / Misc / Mroocheck / FreeWheel / Source / ScrollWin.c < prev    next >
C/C++ Source or Header  |  2000-04-20  |  9KB  |  306 lines

  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. #include <exec/types.h>
  6. #include <intuition/intuition.h>
  7. #include <intuition/screens.h>
  8.  
  9. #include <clib/exec_protos.h>
  10. #include <clib/intuition_protos.h>
  11. #include <clib/gadtools_protos.h>
  12.  
  13. #include "Prefs.h"
  14. #include "GUI.h"
  15. #include "WheelMouse.h"
  16.  
  17. #include "ScrollWin.h"
  18.  
  19. #define HSCROLL_ID 1
  20. #define VSCROLL_ID 2
  21. #define NUDGEPROP_ID 3
  22. #define FORGERAWKEY_ID 4
  23. #define RAWKEYPAGE_ID 5
  24. #define PAGETHRESHOLD_ID 6
  25. #define FAKESCROLLSPEED_ID 7
  26. #define WINDOWMODE_ID 8
  27.  
  28. BOOL ScrollWin_Show(struct ScrollWinContext *pwc);
  29. void ScrollWin_Hide(struct ScrollWinContext *pwc);
  30. BOOL ScrollWin_Handle(struct ScrollWinContext *pwc,unsigned long sigs);
  31. void ScrollWin_Dispose(struct ScrollWinContext *pwc);
  32.  
  33. extern struct WheelMouseContext *MyWM;
  34.  
  35. char *SWinGadTitles[]=
  36. {
  37.   "Prop Gadgets:",
  38.   "H Speed:",
  39.   "V Speed:",
  40.   "Move->Scroll speed:",
  41.   "Enabled:",
  42.   "Shift paging:",
  43.   "Page after %ld lines ",
  44.   "Keypresses:",
  45.   "Scroll Window:",
  46.   NULL
  47. };
  48.  
  49. #define PROPGADGETS_TITLE 0
  50. #define HORIZSPEED_TITLE 1
  51. #define VERTSPEED_TITLE 2
  52. #define FAKESCROLLSPEED_TITLE 3
  53. #define ENABLED_TITLE 4
  54. #define KEYPAGING_TITLE 5
  55. #define PAGETHRESHOLD_TITLE 6
  56. #define KEYPRESSES_TITLE 7
  57. #define WINDOWMODE_TITLE 8
  58.  
  59. BOOL ScrollWin_Show(struct ScrollWinContext *pwc)
  60. {
  61.   struct Gadget *gg;
  62.   int width,width2,leftedge,topedge,tabstop;
  63.   int winleft,wintop;
  64.  
  65.   if(pwc->Visible)
  66.     return(FALSE);
  67.  
  68.   if(!(pwc->Screen=LockPubScreen(NULL)))
  69.     return(FALSE);
  70.  
  71.   if(!(pwc->GUI=GUI_Create(pwc->Screen,pwc->Screen->Font,8,8)))
  72.   {
  73.     pwc->Hide(pwc);
  74.     return(FALSE);
  75.   }
  76.  
  77.   GUI_StringTab(pwc->GUI,SWinGadTitles);
  78.  
  79.   width=GUI_MaxStringWidth(pwc->GUI,MyWM->MidButton.ClickModeNames);
  80.   width2=GUI_MaxStringWidth(pwc->GUI,MyWM->MidButton.DoubleClickModeNames);
  81.   if(width2>width) width=width2;
  82.   width2=GUI_MaxStringWidth(pwc->GUI,MyWM->MidButton.ClickRollModeNames);
  83.   if(width2>width) width=width2;
  84.  
  85.   pwc->GUI->InnerWidth=pwc->GUI->TabStop+width+64;
  86.  
  87.   gg=GUI_BuildCycleGadget(pwc->GUI,SWinGadTitles[WINDOWMODE_TITLE],MyWM->WindowModeNames,WINDOWMODE_ID);
  88.   GT_SetGadgetAttrs(gg,NULL,NULL,GTCY_Active,
  89.                     pwc->Prefs->GetLong(pwc->Prefs,"WindowMode",0),TAG_DONE);
  90.  
  91.   gg=GUI_BuildSlider(pwc->GUI,SWinGadTitles[FAKESCROLLSPEED_TITLE],1,32,17,FAKESCROLLSPEED_ID);
  92.   GT_SetGadgetAttrs(gg,NULL,NULL,GTSL_Level,
  93.                     pwc->Prefs->GetLong(pwc->Prefs,"FakeScrollSpeed",17),TAG_DONE);
  94.  
  95.   gg=GUI_BuildText(pwc->GUI,SWinGadTitles[PROPGADGETS_TITLE]);
  96.  
  97.   gg=GUI_BuildCheckBox(pwc->GUI,SWinGadTitles[ENABLED_TITLE],NUDGEPROP_ID);
  98.   GT_SetGadgetAttrs(gg,NULL,NULL,GTCB_Checked,
  99.                     pwc->Prefs->GetLong(pwc->Prefs,"NudgeProp",TRUE),TAG_DONE);
  100.  
  101.   gg=GUI_BuildSlider(pwc->GUI,SWinGadTitles[HORIZSPEED_TITLE],1,32,17,HSCROLL_ID);
  102.   GT_SetGadgetAttrs(gg,NULL,NULL,GTSL_Level,
  103.                     pwc->Prefs->GetLong(pwc->Prefs,"XScrollSpeed",17),TAG_DONE);
  104.  
  105.   gg=GUI_BuildSlider(pwc->GUI,SWinGadTitles[VERTSPEED_TITLE],1,32,17,VSCROLL_ID);
  106.   GT_SetGadgetAttrs(gg,NULL,NULL,GTSL_Level,
  107.                     pwc->Prefs->GetLong(pwc->Prefs,"YScrollSpeed",17),TAG_DONE);
  108.  
  109.   gg=GUI_BuildText(pwc->GUI,SWinGadTitles[KEYPRESSES_TITLE]);
  110.  
  111.   topedge=pwc->GUI->InnerHeight;
  112.  
  113.   gg=GUI_BuildCheckBox(pwc->GUI,SWinGadTitles[ENABLED_TITLE],FORGERAWKEY_ID);
  114.   GT_SetGadgetAttrs(gg,NULL,NULL,GTCB_Checked,
  115.                     pwc->Prefs->GetLong(pwc->Prefs,"ForgeRawKey",TRUE),TAG_DONE);
  116.  
  117.   tabstop=pwc->GUI->TabStop;
  118.   pwc->GUI->InnerHeight=topedge;
  119.  
  120.   pwc->GUI->TabStop=pwc->GUI->InnerWidth;
  121.   pwc->GUI->TabStop-=gg->Width+8+pwc->GUI->BorderLeft+pwc->GUI->BorderRight;
  122.  
  123.   gg=GUI_BuildCheckBox(pwc->GUI,SWinGadTitles[KEYPAGING_TITLE],RAWKEYPAGE_ID);
  124.   GT_SetGadgetAttrs(gg,NULL,NULL,GTCB_Checked,
  125.                     pwc->Prefs->GetLong(pwc->Prefs,"RawKeyPage",TRUE),TAG_DONE);
  126.  
  127.   pwc->GUI->TabStop=tabstop;
  128.  
  129.   gg=GUI_BuildSliderFormatted(pwc->GUI,SWinGadTitles[PAGETHRESHOLD_TITLE],1,12,4,PAGETHRESHOLD_ID);
  130.   GT_SetGadgetAttrs(gg,NULL,NULL,GTSL_Level,
  131.                     pwc->Prefs->GetLong(pwc->Prefs,"PageThreshold",4),TAG_DONE);
  132.  
  133.  
  134.   if(!(pwc->GUI->LastGadget))
  135.   {
  136.     pwc->Hide(pwc);
  137.     return(FALSE);
  138.   }
  139.  
  140.   winleft=pwc->Prefs->GetLong(pwc->Prefs,"ScrollLeft",0);
  141.   wintop=pwc->Prefs->GetLong(pwc->Prefs,"ScrollTop",1+pwc->Screen->BarHeight);
  142.  
  143.   if(!(pwc->Window=OpenWindowTags(NULL,WA_Left,winleft,
  144.                                        WA_Top,wintop,
  145.                                        WA_InnerWidth,pwc->GUI->InnerWidth,
  146.                                        WA_InnerHeight,pwc->GUI->InnerHeight,
  147.                                        WA_IDCMP,IDCMP_REFRESHWINDOW|IDCMP_CLOSEWINDOW|pwc->GUI->IDCMP,
  148.                                        WA_SizeGadget,FALSE,WA_DragBar,TRUE,
  149.                                        WA_DepthGadget,TRUE,WA_CloseGadget,TRUE,
  150.                                        WA_NewLookMenus,TRUE,
  151.                                        WA_Activate,FALSE,
  152.                                        WA_Title,"Scrolling settings...",TAG_DONE)))
  153.   {
  154.     pwc->Hide(pwc);
  155.     return(FALSE);
  156.   }
  157.  
  158.   pwc->GUI->Attach(pwc->GUI,pwc->Window);
  159.  
  160.   pwc->Signals=1<<pwc->Window->UserPort->mp_SigBit;
  161.  
  162.   pwc->Visible=TRUE;
  163.   return(TRUE);
  164. }
  165.  
  166.  
  167. void ScrollWin_Hide(struct ScrollWinContext *pwc)
  168. {
  169.   if(pwc->Window)
  170.   {
  171.     pwc->Prefs->SetLong(pwc->Prefs,"ScrollTop",pwc->Window->TopEdge);
  172.     pwc->Prefs->SetLong(pwc->Prefs,"ScrollLeft",pwc->Window->LeftEdge);
  173.     CloseWindow(pwc->Window);
  174.   }
  175.   pwc->Window=FALSE;
  176.   pwc->Signals=0;
  177.  
  178.   if(pwc->GUI)
  179.     pwc->GUI->Dispose(pwc->GUI);
  180.   pwc->GUI=NULL;
  181.  
  182.   if(pwc->Screen)
  183.     UnlockPubScreen(NULL,pwc->Screen);
  184.   pwc->Screen=FALSE;
  185.  
  186.   if(pwc->Visible)
  187.     pwc->Visible=FALSE;
  188. }
  189.  
  190.  
  191. void ScrollWin_Dispose(struct ScrollWinContext *pwc)
  192. {
  193.   if(pwc)
  194.   {
  195.     if(pwc->Visible)
  196.       pwc->Hide(pwc);
  197.     free(pwc);
  198.   }
  199. }
  200.  
  201.  
  202. struct ScrollWinContext *ScrollWin_Create(struct PrefsGroup *pg)
  203. {
  204.   struct ScrollWinContext *pwc;
  205.   if(!(pwc=malloc(sizeof(struct ScrollWinContext))))
  206.     return(NULL);
  207.   memset(pwc,0,sizeof(struct ScrollWinContext));
  208.   pwc->Dispose=ScrollWin_Dispose;
  209.   pwc->Handle=ScrollWin_Handle;
  210.   pwc->Hide=ScrollWin_Hide;
  211.   pwc->Show=ScrollWin_Show;
  212.  
  213.   pwc->Prefs=pg;
  214.  
  215.   return(pwc);
  216. }
  217.  
  218.  
  219. BOOL ScrollWin_Handle(struct ScrollWinContext *pwc,unsigned long sigs)
  220. {
  221.   BOOL cont=TRUE,close=FALSE;
  222.   long value;
  223.   char *string;
  224.   if(pwc)
  225.   {
  226.     if(sigs&pwc->Signals)
  227.     {
  228.       struct IntuiMessage *im;
  229.       while(im=GT_GetIMsg(pwc->Window->UserPort))
  230.       {
  231.         int class,code,id;
  232.         struct Gadget *gg;
  233.         class=im->Class;
  234.         code=im->Code;
  235.         switch(class)
  236.         {
  237.           case IDCMP_GADGETUP:
  238.             gg=(struct Gadget *)im->IAddress;
  239.             id=gg->GadgetID;
  240.             GT_ReplyIMsg(im);
  241.             switch(id)
  242.             {
  243.               case HSCROLL_ID:
  244.                 GT_GetGadgetAttrs(gg,pwc->Window,NULL,GTSL_Level,&value,TAG_DONE);
  245.                 pwc->Prefs->SetLong(pwc->Prefs,"XScrollSpeed",value);
  246.                 MyWM->ScrollSpeedX=value;
  247.                 break;
  248.               case VSCROLL_ID:
  249.                 GT_GetGadgetAttrs(gg,pwc->Window,NULL,GTSL_Level,&value,TAG_DONE);
  250.                 pwc->Prefs->SetLong(pwc->Prefs,"YScrollSpeed",value);
  251.                 MyWM->ScrollSpeedY=value;
  252.                 break;
  253.               case FAKESCROLLSPEED_ID:
  254.                 GT_GetGadgetAttrs(gg,pwc->Window,NULL,GTSL_Level,&value,TAG_DONE);
  255.                 pwc->Prefs->SetLong(pwc->Prefs,"FakeScrollSpeed",value);
  256.                 MyWM->FakeScrollSpeed=value;
  257.                 break;
  258.               case PAGETHRESHOLD_ID:
  259.                 GT_GetGadgetAttrs(gg,pwc->Window,NULL,GTSL_Level,&value,TAG_DONE);
  260.                 pwc->Prefs->SetLong(pwc->Prefs,"PageThreshold",value);
  261.                 MyWM->PageThreshold=value;
  262.                 break;
  263.               case NUDGEPROP_ID:
  264.                 GT_GetGadgetAttrs(gg,pwc->Window,NULL,GTCB_Checked,&value,TAG_DONE);
  265.                 pwc->Prefs->SetLong(pwc->Prefs,"NudgeProp",value);
  266.                 MyWM->NudgeProp=value;
  267.                 break;
  268.               case FORGERAWKEY_ID:
  269.                 GT_GetGadgetAttrs(gg,pwc->Window,NULL,GTCB_Checked,&value,TAG_DONE);
  270.                 pwc->Prefs->SetLong(pwc->Prefs,"ForgeRawKey",value);
  271.                 MyWM->ForgeRawKey=value;
  272.                 break;
  273.               case RAWKEYPAGE_ID:
  274.                 GT_GetGadgetAttrs(gg,pwc->Window,NULL,GTCB_Checked,&value,TAG_DONE);
  275.                 pwc->Prefs->SetLong(pwc->Prefs,"RawKeyPage",value);
  276.                 MyWM->RawKeyPage=value;
  277.                 break;
  278.               case WINDOWMODE_ID:
  279.                 GT_GetGadgetAttrs(gg,pwc->Window,NULL,GTCY_Active,&value,TAG_DONE);
  280.                 pwc->Prefs->SetLong(pwc->Prefs,"WindowMode",value);
  281.                 MyWM->WindowMode=value;
  282.                 break;
  283.             }
  284.             break;
  285.           case IDCMP_CLOSEWINDOW:
  286.             GT_ReplyIMsg(im);
  287.             close=TRUE;
  288.             break;
  289.           case IDCMP_REFRESHWINDOW:
  290.             GT_ReplyIMsg(im);
  291.             GT_BeginRefresh(pwc->Window);
  292.             GT_EndRefresh(pwc->Window, TRUE);
  293.             break;
  294.           default:
  295.             GT_ReplyIMsg(im);
  296.             break;
  297.         }
  298.       }
  299.     }
  300.   }
  301.   if(close)
  302.     pwc->Hide(pwc);
  303.   return(cont);
  304. }
  305.  
  306.